﻿singleApp.controller('reportCtrl', ['$http', '$scope', function ($http, $scope) {
    $scope.vm = { num: "" };

    $scope.submit = function () {
        if ($scope.vm.num == undefined || $scope.vm.num == "") {
            layer.msg("请输入数量 !");
            return;
        }

        if (isNaN(parseInt($scope.vm.num))) {
            layer.msg("请输入有效数量 !");
            return;
        }

        //var number = parseInt($scope.vm.num);
        //if (number < 1 || number > 100) {
        //    layer.msg("数量必须在 1 - 100 之间 !");
        //    return;
        //}

        var api_url = window.singleConfig.rootUrl + 'api/user/CommonService/report_post';
        layer.load(2);
        $http({
            method: 'POST',
            url: api_url,
            data: $.param($scope.vm),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        })
		.then(function (result) {
		    var data = result.data;
		    if (data.code == "success") {
		        //layer.closeAll();
		        layer.msg("上报成功!");
		        setTimeout(function () {
		            location.href = data.redirectUrl;
		        }, 500);
		    }
		    else {
		        layer.closeAll();
		        layer.msg(data.message);
		    }
		}, function (data) {
		    layer.msg("系统错误，管理员正在处理!");
		});
    }


}]);